using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace Coding4Fun.Phone.Controls
{
	public class InputPrompt : UserPrompt
	{
		private const string string_1 = "inputBox";
		protected TextBox InputBox;
		public static readonly DependencyProperty InputScopeProperty = DependencyProperty.Register("InputScope", typeof(InputScope), typeof(InputPrompt), null);
		public static readonly DependencyProperty IsSubmitOnEnterKeyProperty = DependencyProperty.Register("IsSubmitOnEnterKey", typeof(bool), typeof(InputPrompt), new PropertyMetadata(true, new PropertyChangedCallback(InputPrompt.smethod_2)));
		public InputScope InputScope
		{
			get
			{
				return (InputScope)base.GetValue(InputPrompt.InputScopeProperty);
			}
			set
			{
				base.SetValue(InputPrompt.InputScopeProperty, value);
			}
		}
		public bool IsSubmitOnEnterKey
		{
			get
			{
				return (bool)base.GetValue(InputPrompt.IsSubmitOnEnterKeyProperty);
			}
			set
			{
				base.SetValue(InputPrompt.IsSubmitOnEnterKeyProperty, value);
			}
		}
		public InputPrompt()
		{
			base.set_DefaultStyleKey(typeof(InputPrompt));
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.InputBox = (base.GetTemplateChild("inputBox") as TextBox);
			if (this.InputBox != null)
			{
				Binding binding = new Binding();
				binding.set_Source(this.InputBox);
				binding.set_Path(new PropertyPath("Text", new object[0]));
				Binding binding2 = binding;
				base.SetBinding(UserPrompt.ValueProperty, binding2);
				this.method_8();
				ThreadPool.QueueUserWorkItem(new WaitCallback(this.method_7));
			}
		}
		private void method_7(object object_0)
		{
			Thread.Sleep(250);
			base.get_Dispatcher().BeginInvoke(new Action(this.method_9));
		}
		private static void smethod_2(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			InputPrompt inputPrompt = dependencyObject_0 as InputPrompt;
			if (inputPrompt != null)
			{
				inputPrompt.method_8();
			}
		}
		private void method_8()
		{
			this.InputBox = (base.GetTemplateChild("inputBox") as TextBox);
			if (this.InputBox == null)
			{
				return;
			}
			this.InputBox.remove_KeyDown(new KeyEventHandler(this.InputBox_KeyDown));
			if (this.IsSubmitOnEnterKey)
			{
				this.InputBox.add_KeyDown(new KeyEventHandler(this.InputBox_KeyDown));
			}
		}
		private void InputBox_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.get_Key() == 3)
			{
				this.OnCompleted(new PopUpEventArgs<string, PopUpResult>
				{
					Result = base.Value,
					PopUpResult = PopUpResult.Ok
				});
			}
		}
		[CompilerGenerated]
		private void method_9()
		{
			this.InputBox.Focus();
			this.InputBox.SelectAll();
		}
	}
}
